package cn.edu360.hadoop.util;

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

import cn.edu360.hadoop.constant.HdfsConstant;
import cn.edu360.hadoop.factory.HdfsFileSystem;
import cn.edu360.hadoop.factory.HdfsFileSystemFactory;

public final class HdfsFileSystemUtil {


    public static FileSystem getCli(Configuration conf) {
        FileSystem fs = null;

        try {
            fs = FileSystem.get(new URI(HdfsConstant.HDFS_SERVER_URI), conf, HdfsConstant.HDFS_SERVER_USER);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return fs;
    }

    
    /**
     * 获取HDFS对象处理工厂
     * @return HdfsFileSystemFactory
     */
    public static HdfsFileSystemFactory get () {
    	return new HdfsFileSystem();
    }

    /**
     * 关闭
     *
     * @param fs
     */
    public static void close(FileSystem fs) {

        try {

            if (fs != null) {
                fs.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
